<template>
	<view class="service-wrapper absolute">
		<u-popup round="16rpx" :show="show" bgColor="rgba(0,0,0,0)" mode="center" @close="closeHandle">
			<view class="service-popup-inner">
				<view class="service-list">
					<view class="service-btn-item" style="--service-color:#8BDCFF">
						<u-button @click="callPhone" text="拨打电话" />
					</view>
					<view class="service-btn-item active" style="--service-color:#B09FFE">
						<u-button open-type="contact" @click="connectService" text="在线客服" />
					</view>
				</view>
				<view class="close-wrapper">
					<image class="close-icon" @click="closeHandle" :src="sourceUrl + '/close-circle.png'"
						mode="aspectFill"></image>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		props: {
			show: {
				type: Boolean,
				default: () => false
			}
		},
		watch: {
			show(value) {
				if (!value) return
				this.initData()
			}
		},
		data() {
			return {
				mobile: ''
			}
		},

		methods: {
			async initData() {
				const resp = await this.$request({
					url: "/index/getCustomerService",
				})
				const { code, data, msg } = resp
				if (code !== 1) return this.$toast({ title: msg }, () => {
					this.closeHandle()
				})
				if (!data || !data.length) return
				const [target] = data
				this.mobile = target.mobile
			},
			connectService() {

			},
			callPhone() {
				uni.makePhoneCall({
					phoneNumber: this.mobile,
				})
			},
			closeHandle() {
				this.$emit('close', false)
			},
		},
	}
</script>

<style lang="scss" scoped>
	.service-wrapper {
		.service-popup-inner {
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			overflow: hidden;

			.close-wrapper {
				margin-top: 30rpx;
				display: flex;
				align-items: center;
				justify-content: center;

				.close-icon {
					width: 80rpx;
					height: 80rpx;
				}
			}

			.service-list {
				border-radius: 16rpx 16rpx 16rpx 16rpx;
				overflow: hidden;
				padding: 116rpx 104rpx;
				box-sizing: border-box;
				background-color: #FFF;

				.service-btn-item {
					margin-bottom: 64rpx;

					&:last-child {
						margin-bottom: 0;
					}

					::v-deep button {
						width: 272rpx;
						height: 92rpx;
						background: var(--service-color);
						border-radius: 8rpx 8rpx 8rpx 8rpx;
						font-size: 28rpx;
						color: #FFFFFF;
					}
				}
			}
		}
	}
</style>